package com.fr.report.cellElement.core;

import com.fr.base.FCloneable;
import com.fr.base.FRContext;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.LinkWorkBookTemplate;
import com.fr.report.Report;
import com.fr.report.TemplateReport;
import com.fr.report.TemplateWorkBook;
import com.fr.report.WorkBook;
import com.fr.report.core.KV;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SubReport
  implements XMLable
{
  public static final String XML_TAG = "SubReport";
  private TemplateWorkBook packee;
  private KV[] parameterKVS;
  private boolean isExtendOwnerParameters;

  public SubReport()
  {
    this(new WorkBook());
  }

  public SubReport(TemplateWorkBook paramTemplateWorkBook)
  {
    this.isExtendOwnerParameters = false;
    this.packee = paramTemplateWorkBook;
  }

  public TemplateWorkBook getPackee()
  {
    return this.packee;
  }

  public void setPackee(TemplateWorkBook paramTemplateWorkBook)
  {
    this.packee = paramTemplateWorkBook;
  }

  public KV[] getParameterKVS()
  {
    return this.parameterKVS;
  }

  public void setParameterKVS(KV[] paramArrayOfKV)
  {
    this.parameterKVS = paramArrayOfKV;
  }

  public boolean isExtendOwnerParameters()
  {
    return this.isExtendOwnerParameters;
  }

  public void setExtendOwnerParameters(boolean paramBoolean)
  {
    this.isExtendOwnerParameters = paramBoolean;
  }

  public ResultSubReport execute(Map paramMap)
  {
    return new ResultSubReport(this.packee.execute(paramMap));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("packee"))
        if ((str2 = paramXMLableReader.getAttr("class")) != null)
          try
          {
            Object localObject2;
            Object localObject1 = null;
            if (str2.endsWith(".LinkReportTemplate"))
              localObject2 = new LinkWorkBookTemplate();
            else
              localObject2 = Class.forName(str2).newInstance();
            if (localObject2 instanceof TemplateWorkBook)
            {
              localObject1 = (TemplateWorkBook)localObject2;
              setPackee((TemplateWorkBook)localObject1);
              paramXMLableReader.readXMLObject((XMLReadable)localObject1);
            }
            else if (localObject2 instanceof TemplateReport)
            {
              localObject1 = new WorkBook();
              ((TemplateWorkBook)localObject1).addReport("Compatible0651WorkSheet", (TemplateReport)localObject2);
              setPackee((TemplateWorkBook)localObject1);
              paramXMLableReader.readXMLObject((Report)localObject2);
              ((TemplateWorkBook)localObject1).setReportName(0, "sheet1");
            }
          }
          catch (Exception localException)
          {
            FRContext.getLogger().log(Level.WARNING, "Failed to read subReport");
          }
      else if (("KVS".equals(str1)) || ("KTVS".equals(str1)))
        this.parameterKVS = KV.readKTVArray(paramXMLableReader);
      else if ("SubReportAttr".equals(str1))
        if ((str2 = paramXMLableReader.getAttr("extendOwnerParameter")) != null)
          this.isExtendOwnerParameters = Boolean.valueOf(str2).booleanValue();
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("SubReportAttr");
    if (this.isExtendOwnerParameters)
      paramXMLPrintWriter.attr("extendOwnerParameter", this.isExtendOwnerParameters);
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("packee").attr("class", this.packee.getClass().getName());
    this.packee.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("KVS");
    int i = 0;
    int j = (this.parameterKVS == null) ? 0 : this.parameterKVS.length;
    while (i < j)
    {
      if (this.parameterKVS[i] == null)
        break label120:
      this.parameterKVS[i].writeXML(paramXMLPrintWriter);
      label120: ++i;
    }
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    SubReport localSubReport = (SubReport)super.clone();
    localSubReport.setPackee((TemplateWorkBook)this.packee.clone());
    if (this.parameterKVS != null)
    {
      ArrayList localArrayList = new ArrayList();
      for (int i = 0; i < this.parameterKVS.length; ++i)
        if (this.parameterKVS[i] == null)
          localArrayList.add(null);
        else
          localArrayList.add(this.parameterKVS[i].clone());
      localSubReport.setParameterKVS((KV[])localArrayList.toArray(new KV[localArrayList.size()]));
    }
    return localSubReport;
  }
}